﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using WarehouseManager.Core;
using WarehouseManager.Model;

namespace WarehouseManager.DataAccess
{
    class PhieuxuatAccess
    {
        dbConnection dbCon = new dbConnection();
        public PhieuxuatAccess()
        {

        }
        public DataTable laytoanbophieuxuat(){
            return dbCon.executeSelectProcedureQueryNonParameter("proc_selectPhieuXuat");
        }

        public DataView timkiemMapx(string maPX)
        {
            DataView dataView = laytoanbophieuxuat().DefaultView;
            dataView.RowFilter = string.Format("maPX like '%{0}%'", maPX);
            return dataView;
        }
        public void themPhieuxuat(Phieuxuat pn)
        {
            SqlParameter[] listParams = new SqlParameter[4];
            SqlParameter maPX = new SqlParameter("@maPX", SqlDbType.VarChar, 10);
            maPX.Value = pn.maPX1;
            SqlParameter maKH = new SqlParameter("@maKH", SqlDbType.VarChar, 10);
            maKH.Value = pn.maKH1;
            SqlParameter maNV = new SqlParameter("@maNV", SqlDbType.VarChar, 10);
            maNV.Value = pn.maNV1;
            listParams[0] = maPX;
            listParams[1] = maKH;
            listParams[2] = new SqlParameter("@ngayXuat", string.Format("{0:yyyy-MM-dd}", pn.ngayXuat1));
            listParams[3] = maNV;
            dbCon.executeInsertProcedureQuery("proc_insertPhieuXuat", listParams);
        }
        public void suaPhieuxuat(Phieuxuat pn)
        {
            SqlParameter[] listParams = new SqlParameter[4];
            SqlParameter maPX = new SqlParameter("@maPX", SqlDbType.VarChar, 10);
            maPX.Value = pn.maPX1;
            SqlParameter maKH = new SqlParameter("@maKH", SqlDbType.VarChar, 10);
            maKH.Value = pn.maKH1;
            SqlParameter maNV = new SqlParameter("@maNV", SqlDbType.VarChar, 10);
            maNV.Value = pn.maNV1;
            listParams[0] = maPX;
            listParams[1] = maKH;
            listParams[2] = new SqlParameter("@ngayXuat", string.Format("{0:yyyy-MM-dd}", pn.ngayXuat1));
            listParams[3] = maNV;
            dbCon.executeUpdateProcedureQuery("proc_updatePhieuXuat", listParams);
        }
        public void xoaPhieuxuat(Phieuxuat px)
        {
            SqlParameter[] listParams = new SqlParameter[1];
            SqlParameter mapx = new SqlParameter("@maPX", SqlDbType.VarChar, 10);
            mapx.Value = px.maPX1;
            listParams[0] = mapx;
            dbCon.executeDeleteProcedureQuery("proc_deletePhieuXuat", listParams);
        }
        public DataTable layView(string s)
        {
            SqlParameter[] listParams = new SqlParameter[1];
            SqlParameter mapx = new SqlParameter("@maPX", SqlDbType.VarChar, 10);
            mapx.Value = s;
            listParams[0] = mapx;
            return dbCon.executeSelectProcedureQuery("proc_selectIDViewPhieuXuat", listParams);
        }
        public DataTable layHanghoatheoMapx(string s)
        {
            SqlParameter[] listParams = new SqlParameter[1];
            SqlParameter mapx = new SqlParameter("@maPX", SqlDbType.VarChar, 10);
            mapx.Value = s;
            listParams[0] = mapx;
            return dbCon.executeSelectProcedureQuery("tt_listHanghoa_PX", listParams);
        }
    }
}
